using 第二次作业.entity.impl;
using 第二次作业.entity;
using Rectangle= 第二次作业.entity.impl.Rectangle;
using Square= 第二次作业.entity.impl.Square;
using Circle= 第二次作业.entity.impl.Circle;

namespace 第二次作业
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 随机创建10个形状对象
            Random random = new Random();
            List<Shape> shapes = new List<Shape>();
            for (int i = 0; i < 10; i++)
            {
                int shapeType = random.Next(3);
                switch (shapeType)
                {
                    case 0:
                        Rectangle rectangle = new Rectangle(random.Next(1, 10), random.Next(1, 10));
                        resText.Text += new String($"长方形的长为：{rectangle.Length}，宽为：{rectangle.Width}，面积为：{rectangle.Area()}");
                        resText.Text += new String(Environment.NewLine);
                        shapes.Add(rectangle);
                        break;
                    case 1:
                        Square square = new Square(random.Next(1, 10));
                        resText.Text += new String($"正方形的边长为：{square.Length}，面积为：{square.Area()}");
                        resText.Text += new String(Environment.NewLine);
                        shapes.Add(square);
                        break;
                    case 2:
                        Circle circle = new Circle(random.Next(1, 10));
                        resText.Text += new String($"圆形的半径为：{circle.Radius}，面积为：{circle.Area()}");
                        resText.Text += new String(Environment.NewLine);
                        shapes.Add(circle);
                        break;
                }
            }

            // 计算面积之和
            double totalArea = 0;
            foreach (Shape shape in shapes)
            {
                if (shape.IsLegal())
                {
                    totalArea += shape.Area();
                }
            }

            // 显示面积之和
            resText.Text += new String($"面积之和为：{totalArea}");
        }
    }
}